programming4us
           
 
 
Programming

jQuery 1.3 : Compact forms (part 2) - AJAX auto-completion

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
12/14/2010 3:48:29 PM

AJAX auto-completion

We can further spruce up our search field by offering auto-completion of its contents. This feature will allow users to type the beginning of a search term and be presented with all of the possible terms that begin with the typed string. Since the list of terms can be drawn from a database that is driving the site, the user can know that search results are forthcoming if the typed term is used. Also, if the database provides the terms in order of popularity or number of results, the user can be guided to more appropriate searches.

Auto-completion is a very complicated subject with subtleties introduced by different kinds of user interaction. We will craft a working example here, but cannot, in this space, explore all of the advanced concepts such as limiting the rate of requests or multi-term completion. The auto-complete widget in the jQuery UI plugin collection is recommended for simple, real-world implementations, and as a starting point for more complex ones. It can be found at http://ui.jquery.com/.

The basic idea behind an auto-completion routine is to react to a keystroke, and to send an AJAX request to the server containing the contents of the field in the request. The results will contain a list of possible completions for the field. The script then presents this list as a dropdown below the field.

On the server

We need some server-side code to handle requests. While a real-world implementation will usually rely on a database to produce a list of possible completions, for this example we can use a simple PHP script with the results built in:

<?php
if (strlen($_REQUEST['search-text']) < 1) {
print '[]';
exit;
}
$terms = array(
'access',
'action',
// List continues...
'xaml',
'xoops',
);
$possibilities = array();
foreach ($terms as $term) {
if (strpos($term, strtolower($_REQUEST['search-text']))
=== 0) {
$possibilities[] = "'". str_replace("'", "\\'", $term)
."'";
}
}
print ('['. implode(', ', $possibilities) .']');

The page compares the provided string against the beginning of each term, and composes a JSON array of matches. The string manipulation operations here (such as and implode()) ensure that the output of the script is properly-formatted JSON, so as to avoid JavaScript errors during parsing. str_replace()

Other -----------------
- The Art of SEO : Duplicate Content Issues (part 3)
- The Art of SEO : Duplicate Content Issues (part 2) - How Search Engines Identify Duplicate Content
- The Art of SEO : Duplicate Content Issues (part 1) - Consequences of Duplicate Content
- The Art of SEO : Content Optimization (part 2)
- The Art of SEO : Content Optimization (part 1)
- iPad SDK : New Graphics Functionality - Introducing Dudel (part 2)
- iPad SDK : New Graphics Functionality - Introducing Dudel (part 1)
- iPad SDK : New Graphics Functionality - Bezier Paths
- CSS for Mobile Browsers : Where to Insert the CSS (part 2) - Media queries
- CSS for Mobile Browsers : Where to Insert the CSS (part 1) - Media Filtering
- Developing an SEO-Friendly Website : Keyword Targeting (part 4)
- Developing an SEO-Friendly Website : Keyword Targeting (part 3)
- Developing an SEO-Friendly Website : Keyword Targeting (part 2)
- Developing an SEO-Friendly Website : Keyword Targeting (part 1) - Title Tags
- The Art of SEO : Optimization of Domain Names/URLs
- Cloud Security and Privacy : Regulatory/External Compliance (part 2)
- Cloud Security and Privacy : Regulatory/External Compliance (part 1)
- Developing an SEO-Friendly Website : Root Domains, Subdomains, and Microsites (part 2)
- Developing an SEO-Friendly Website : Root Domains, Subdomains, and Microsites (part 1)
- Parallel Programming with Microsoft .Net : Parallel Aggregation - An Example
 
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us